package com.ssy.lingxi.member.merchant.repository;

import com.ssy.lingxi.member.merchant.entity.MemberRightSpendHistoryDO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * 会员权益消费记录操作Repository
 * @author 万宁
 * @version 2.0.0
 * @date 2020-07-15
 */
@Repository
public interface MemberRightSpendHistoryRepository extends JpaRepository<MemberRightSpendHistoryDO, Long>, JpaSpecificationExecutor<MemberRightSpendHistoryDO> {

    Page<MemberRightSpendHistoryDO> findByMemberIdAndRoleIdAndSubMemberIdAndSubRoleId(Long upperMemberId, Long upperRoleId, Long subMemberId, Long subRoleId, Pageable pageable);

    @Transactional
    void deleteAllBySubMemberIdAndSubRoleId(Long subMemberId, Long subRoleId);

    @Transactional
    void deleteByMemberIdAndRoleIdAndSubMemberIdAndSubRoleId(Long memberId, Long roleId, Long subMemberId, Long subRoleId);

    MemberRightSpendHistoryDO findFirstByBusinessNoAndSpendTypeEnum(String businessNo,Integer spendTypeEnum);
}
